{% extends 'base_user_center.html' %}
{% load staticfiles %}
{% block right_content %}
    <h3 class="common_title2">支付测试页面</h3>

   	<div class="order_submit clearfix">
        <form method="post" action="/user/mytest_pay/">
            {% csrf_token %}
                <li>
{#                    <input type="text" value="{{ order_id }}">#}
                    <input type="text" name="order_id" value="{{ order_id }}">
                </li>
                <li class="pay_sub">
                    <input type="submit" value="确认付款">
                </li>
        </form>


{#        {% csrf_token %}#}
{#		<a href="javascript:;" order_id ="{{ order_id }}" id="pay_btn">确认付款</a>#}
	</div>
{% endblock right_content %}

{% block bottomfiles %}
	<script type="text/javascript">
		$('#pay_btn').click(function() {
		    // 1.获取addr_id, pay_style, cart_id_list
            order_id = $(this).attr('order_id')
            csrf = $('input[name="csrfmiddlewaretoken"]').val()
            // alert(addr_id+':'+pay_method+':'+cart_id_list)
            // 发起一个ajax post请求
            params = {'order_id':order_id, 'csrfmiddlewaretoken':csrf}
            $.post('/user/mytest_pay/', params, function (data) {
                // {'res':0} 库存不足
                // {'res':1} 提交成功
                // {'res':2} 订单错误
                if (data.res == 0){
                    alert('库存不足')
                }
                else
                {
                    // 订单成功
                    localStorage.setItem('order_finish',2);
                    $('.popup_con').fadeIn('fast', function() {
                        setTimeout(function(){
                            $('.popup_con').fadeOut('fast',function(){
                                window.location.href = '{% url 'user_order' '' %}';
                            });
                        },3000)

                    });
                }
            })
		});
	</script>
{% endblock bottomfiles %}